package com.zuo.mall.controller;

import com.zuo.mall.common.api.CommonPage;
import com.zuo.mall.common.api.CommonResult;
import com.zuo.mall.dto.PmsProductCategoryWithChildrenItem;
import com.zuo.mall.entity.PmsProductCategory;
import com.zuo.mall.service.PmsProductCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.Authorization;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api("分类管理")
@RestController
@RequestMapping("productCategory")
public class PmsProductCategoryController {
    @Autowired
    private PmsProductCategoryService productCategoryService;
    @GetMapping("/list/withChildren")
    public CommonResult<List<PmsProductCategoryWithChildrenItem>> listWithChildren() {
        List<PmsProductCategoryWithChildrenItem> list= productCategoryService.listWithChildren();
        return CommonResult.success(list);
    }

    @GetMapping("/list/{parentId}")
    public CommonResult getList(
            @PathVariable("parentId") Long parentId,
            @RequestParam("pageNum") Integer pageNum,
                                @RequestParam("pageSize") Integer pageSize) {
        CommonPage<PmsProductCategory> commonPage = productCategoryService.getList(parentId, pageSize, pageNum);
        return CommonResult.success(commonPage);
    }

    /**
     * 根据Id获取商品分类
     */
    @GetMapping("{id}")
    public CommonResult getItem(@PathVariable("id") Long id) {
        PmsProductCategory byId = productCategoryService.getById(id);
        return CommonResult.success(byId);
    }
}
